<?php
	header('content-type:text/html;charset=utf-8'); 
	//重要!兩種情況中都要判斷DID是否存在,DID不存在,還要判斷工單號和機台號是否為空
	//2018-3-16 11:08:32注釋:想起來好像前端就應該做判斷過濾掉這種情況
	//$GX=$_GET["nos"];
	
	$Working_Pro = $_POST["Working_Pro"];//工序
	$Shift = $_POST["Shift"];//班別
	$department = $_POST["department"];//时间
	$conn=mysql_connect("127.0.0.1:3306","root","tdled2018");
	if (!$conn){
		die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("tddb", $conn);
	
	mysql_query("set character set 'utf8'");//读库 
	
	mysql_query("set names 'utf8'");//写库 
	
	$sql="
	SELECT  
		`work_number` ,  `name` 
	FROM  
		`operator_scheduling` 
	WHERE  
		`department` =  '".$department."'
	AND 
		`Working_Pro` ='".$Working_Pro."'
	AND  
		`Shift` =  '".$Shift."'
	AND  `Times` 
	IN (

	SELECT 
		MAX( Times ) 
	FROM 
		operator_scheduling
	WHERE  
		`department` =  '".$department."'
)
	
	";
	
	$result = mysql_query($sql); 
	
	$dbdata = array();
	
	//Fetch into associative array
	while ( $row = mysql_fetch_array($result))  {
		//echo json_encode($row)."</br>";
		$dbdata[]=$row;
	}
	
	//Print array in JSON format
	echo json_encode($dbdata);
	
	
?>